reset_forced_key
This function causes a given key to reset its state of being forced to pass control back to the user.
bool reset_forced_key(int key)
Parameters:
key
One of the BGT key name constants, see appendix A for a full list.
Return value:
true if the key's state is reset successfully, false if an error occurs.
Remarks:
Forcing keys is useful for controlling certain aspects of games. For example, if you wanted a game to completely replay itself in the player's style, you might record the code and length of each key pressed in a previous game, and code the replay so that all the keys are forced up or down at the right moments, thereby completely simulating the player's actions.
This function should be called after the use of either the force_key_down or force_key_up function. To reset the state of all keys, use the reset_all_forced_keys function.
Example:
/*
This is a small example that plays the Windows ding every second while the space bar is pressed. If the f key is pressed, the script will force the space key down, thereby triggering the ding to play whether the space bar is physically pressed or not. Pressing the r key will reset the state.
*/
void main()
{
sound ding;
timer time;
ding.load("c:/windows/media/ding.wav");
show_game_window("Ding Test");
while(true)
{
if((time.elapsed<1000)||(!key_down(KEY_SPACE)))
{
if((key_pressed(KEY_ESCAPE))||((key_down(KEY_LMENU))&&(key_pressed(KEY_F4))))
{
exit();
}
if(key_pressed(KEY_F))
{
force_key_down(KEY_SPACE);
}
if(key_pressed(KEY_R))
{
reset_forced_key(KEY_SPACE);
}
wait(5);
continue;
}
time.restart();
ding.play();
}
}